import allure
import pytest


@pytest.hookimpl(tryfirst=True, hookwrapper=True)
def pytest_runtest_makereport(item, call):
    outcome = yield
    report = outcome.get_result()
    if report.when == "call":
        test_instance = getattr(item, "instance", None)
        if test_instance is not None:
            driver = getattr(test_instance, "driver", None)
            if driver:
                img = driver.get_screenshot_as_png()
                allure.attach(img, "End screen shot", attachment_type=allure.attachment_type.PNG)
